package com.yyh.xiancheng;

public class Demo3 {
    public static void main(String[] args) {
        //创建线程任务子类对象
        MyRunnable r = new MyRunnable();
        //创建线程对象
        Thread t1 = new Thread(r,"线程1");
        //启动线程
        t1.start();
        MyRunnable2 r2 = new MyRunnable2();
        //创建线程对象
        Thread t2 = new Thread(r,"线程2");
        //启动线程
        t2.start();
        //创建线程对象
        Thread t3 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 200; i <= 300; i++) {
                    System.out.println(Thread.currentThread().getName()+"：" + i);
                }
            }
        }, "线程3");
        //启动线程
        t3.start();
        //创建线程对象
        Thread t4 = new Thread(() -> {
            for (int i = 100; i <= 200; i++) {
                System.out.println(Thread.currentThread().getName()+"：" + i);
            }
        }, "线程4");
        //启动线程
        t4.start();
    }
}
//创建实现Runnable接口的类
class MyRunnable implements Runnable{
    @Override
    public void run() {
        for (int i = 200; i <= 300; i++) {
            System.out.println(Thread.currentThread().getName()+"：" + i);
        }
    }
}
//创建实现Runnable接口的类
class MyRunnable2 implements Runnable{
    @Override
    public void run() {
        for (int i = 100; i <= 200; i++) {
            System.out.println(Thread.currentThread().getName()+"：" + i);
        }
    }
}
